<?php

namespace Tbf\Component\CallNum;

use Tbf\Component\Crypto\Random;

class CallNumFunction
{
    static $call_num_map = array();
    /**
     * 返回某个关键词调用的次数(全局)
     * @param $id
     * @return mixed
     * @deprecated
     */
    public static function getCallNum($id)
    {
        return self::addOne($id);
    }

    /**
     * 仅获取某个id的调用次数,不增加调用次数
     * @param $id
     * @return mixed
     */
    public static function get($id){
        if (empty(self::$call_num_map[$id])) {
            self::$call_num_map[$id]=0;
        }
        return self::$call_num_map[$id];
    }
    public static function addOne($id){
        if (empty(self::$call_num_map[$id])) {
            self::$call_num_map[$id]=0;
        }
        self::$call_num_map[$id]+=1;

        return self::$call_num_map[$id];
    }
    /**
     * 返回一个id
     */
    public static function newId(){
        return Random::hex(8);
    }
}
